/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package cloud.coder.remote.grpc.server.handler;

import cloud.coder.remote.grpc.server.GRPCHandler;
import io.grpc.examples.network.common.Commands;
import io.grpc.examples.network.management.InstancePingPkg;
import io.grpc.examples.network.management.InstanceProperties;
import io.grpc.examples.network.management.ManagementServiceGrpc;
import io.grpc.stub.StreamObserver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ManagementServiceHandler extends ManagementServiceGrpc.ManagementServiceImplBase implements GRPCHandler {
    private static final Logger LOGGER = LoggerFactory.getLogger(ManagementServiceHandler.class);

    public ManagementServiceHandler() {
    }

    @Override
    public void reportInstanceProperties(final InstanceProperties request,
                                         final StreamObserver<Commands> responseObserver) {

        LOGGER.info(request.toString());
        responseObserver.onNext(Commands.newBuilder().build());
        responseObserver.onCompleted();
    }

    @Override
    public void keepAlive(final InstancePingPkg request, final StreamObserver<Commands> responseObserver) {
        LOGGER.info("接收到客户端{}[{}]的心跳",request.getService(),request.getServiceInstance());
        responseObserver.onNext(Commands.newBuilder().build());
        responseObserver.onCompleted();
    }
}
